package com.isunland.managesystem.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.PlanList.PlanCheckList;
import java.util.List;

public class PlanApproveAdapter extends ArrayAdapter<PlanCheckList> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2015-08-17 14:14:10 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    final TextView tvContentPlanApprove;
    final TextView tvPersonPlanApprove;
    final TextView tvTimePlanApprove;

    private ViewHolder(LinearLayout rootView, TextView tvContentPlanApprove,
        TextView tvPersonPlanApprove, TextView tvTimePlanApprove) {
      this.rootView = rootView;
      this.tvContentPlanApprove = tvContentPlanApprove;
      this.tvPersonPlanApprove = tvPersonPlanApprove;
      this.tvTimePlanApprove = tvTimePlanApprove;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvContentPlanApprove = (TextView) rootView.findViewById(R.id.tv_content_planApprove);
      TextView tvPersonPlanApprove = (TextView) rootView.findViewById(R.id.tv_person_planApprove);
      TextView tvTimePlanApprove = (TextView) rootView.findViewById(R.id.tv_time_planApprove);

      return new ViewHolder(rootView, tvContentPlanApprove, tvPersonPlanApprove, tvTimePlanApprove);
    }
  }

  @NonNull @Override
  public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_plan_approve, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    PlanCheckList item = getItem(position);

    vh.tvContentPlanApprove.setText(item != null ? item.getPlanContentDesc() : null);
    vh.tvPersonPlanApprove.setText(item != null ? item.getExcManName() : null);
    vh.tvTimePlanApprove.setText(
        getContext().getString(R.string.planEsteTime, item != null ? item.getPlanEsteTime() : ""));

    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors
  public PlanApproveAdapter(Context context, List<PlanCheckList> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

}
